import { url, BaseRequest } from '@/core/request/base-request'
import { Demo } from '@/model/demo'

export class DemoApi extends BaseRequest implements R.ApiDeleteAble {
  @url('/getlist')
  async getList(key: string, page: R.Page) {
    let time = Date.now()
    return Promise.resolve({
      total: 100,
      list: new Array(page.pageSize)
        .fill({
          id: time,
          name: '张三' + '|' + page.pageNo + '/' + page.pageSize + '|' + key,
          account: 'zhangsan',
          sex: 'male',
          age: '12345',
        })
        .map((item, index) => {
          item = Object.assign({}, item)
          item.id = item.id + index + ''
          item.name += index
          return item
        }) as Demo[],
    })
  }
  @url('/delete')
  async deleteRows(ids: string[]): Promise<any> {
    return Promise.resolve({})
  }
  @url('/get-row')
  async getRow(id: string): Promise<Demo> {
    return Promise.resolve(Demo.from({ id }))
  }
  @url('/save-row')
  async saveRow(data: Demo): Promise<Demo> {
    return Promise.resolve(data)
  }
}

export default new DemoApi()
